import React ,{Component}from 'react';
import { Link,Redirect } from 'react-router-dom';
class Home extends Component {
    constructor(props) {
        super(props);
        this.state = { 
            list:[
                {cid:123,title:'小羊的个人博客'},
                {cid:456,title:'小羊的文章'},
                {cid:789,title:'小羊的视频'},
            ]
         }
         //编程式重定向，重定向页面特性不能返回
         this.props.history.push("/list/重定向")
    }
    componentDidMount() {
        console.log(this.props)
    }
    render() { 
        return ( 
            <div>
                {/* 声明式重定向 */}
                {/* <Redirect to="/list/1"/> */}
                <h1>Home</h1>
                <ol>
                    {
                        this.state.list.map((item,index)=>(
                            <li key={index}>
                                <Link to={'/list/' + item.cid}> {item.title}</Link>
                            </li>
                        ))
                    }
                </ol>
            </div>
         );
    }
}
 
export default Home;